package com.easy;

import java.util.Stack;

/**
 * Created by Lxk on 2020/2/16.
 */
public class Solution1221 {

    public int balancedStringSplit(String s) {
        Stack<Character> stack = new Stack<>();
        int count = 0;
        int pos = 0;
        while (pos < s.length()) {
            char ch = s.charAt(pos);
            if (!stack.isEmpty()) {
                if (stack.peek() == ch) {
                    stack.push(ch);
                } else {
                    stack.pop();
                }
            } else {
                stack.push(ch);
            }
            if (stack.isEmpty()) {
                count++;
            }
            pos++;
        }
        return count;
    }

    public static void main(String[] args) {
        Solution1221 solution1221 = new Solution1221();
        System.out.println(solution1221.balancedStringSplit("RLRRLLRLRL"));
    }

}
